package com.rem.concurrency.multithreading;

import lombok.SneakyThrows;

/**
 * 线程插队
 *
 * @author Rem
 * @date 2021-03-03
 */

public class ThreadJoin implements Runnable {

    @SneakyThrows
    public static void main(String[] args) {
        ThreadJoin threadJoin = new ThreadJoin();
        Thread joinTest = new Thread(threadJoin, "joinTest");
        joinTest.start();

        for (int i = 0; i < 100; i++) {
            if (i == 50) {
                joinTest.join();
            }
            System.out.println("main:" + i);
        }

    }

    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            System.out.println(Thread.currentThread().getName() + "---->" + i);
        }
    }
}
